import hashlib
from sqlalchemy import create_engine
from xpinyin import Pinyin

# engine = create_engine("mysql+pymysql://root:qian1230.@113.31.103.147/doc", encoding="utf-8", echo=True, max_overflow=50)
engine = create_engine("mysql+pymysql://root:5200Love.@106.75.171.130/doc", encoding="utf-8", echo=True,
                       max_overflow=50)
import uuid


def getuid():
    return uuid.uuid1()


# MD5 加密
def md5(str):
    md5 = hashlib.md5()
    md5.update(str.encode('utf-8'))
    return md5.hexdigest()


def chineseToSpell(word):
    ''' 根据汉字转换成拼音 '''
    p = Pinyin()
    result = p.get_pinyin(word)
    str = ""
    for i in [i[0] for i in result.split("-")]:
        str += i
    return str


# 返回参数格式
def returnPara(code, msg, data):
    return {"code": code, "msg": msg, "data": data}


def insert_respond(result):
    if result:
        res = {"msg": result}
        return res
    else:
        return {"msg": "-1"}


def serialize(result):
    data = []
    for i in result:
        data.append(i.to_json())
    return data


def judge_status(result):
    if result != -1:
        return returnPara(200, "success", result)
    else:
        return returnPara(500, "default", result)


if __name__ == '__main__':
    # md = md5("dada")
    # print(type(md))

    print(chineseToSpell("肺热"))
